/*
 * Copyright (c) 2018-2999 九五云信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.distribution.platform.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.annotation.SysLog;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.distribution.comment.model.DistributionUserWalletBill;
import com.yami.shop.distribution.comment.service.DistributionUserWalletBillService;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 分销员钱包流水
 *
 * @author xwc
 * @date 2019-04-29 16:39:13
 */
@RestController
@AllArgsConstructor
@RequestMapping("/distribution/distributionUserWalletBill")
public class DistributionUserWalletBillController {

    private final DistributionUserWalletBillService distributionUserWalletBillService;

    /**
     * 分页查询
     *
     * @param page                       分页对象
     * @param distributionUserWalletBill 分销员钱包流水
     * @return 分页数据
     */
    @GetMapping("/page")
    public ResponseEntity<IPage<DistributionUserWalletBill>> getDistributionUserWalletBillPage(PageParam<DistributionUserWalletBill> page, DistributionUserWalletBill distributionUserWalletBill) {
        return ResponseEntity.ok(distributionUserWalletBillService.page(page, new LambdaQueryWrapper<DistributionUserWalletBill>()));
    }

    /**
     * 分页查询(携带UserVO)
     *
     * @param page       分页对象
     * @param userMobile 分销员手机号
     * @return 分页数据
     */
    @GetMapping("/pageAndUser")
    public ResponseEntity<IPage<DistributionUserWalletBill>> getDistributionUserWalletBillAndUserPage(PageParam page, String userMobile) {
        return ResponseEntity.ok(distributionUserWalletBillService.getDistributionUserWalletBillAndUserPage(page, userMobile));
    }


    /**
     * 通过id查询分销员钱包流水
     *
     * @param id id
     * @return 单个数据
     */
    @GetMapping("/info/{id}")
    public ResponseEntity<DistributionUserWalletBill> getById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(distributionUserWalletBillService.getById(id));
    }

    /**
     * 新增分销员钱包流水
     *
     * @param distributionUserWalletBill 分销员钱包流水
     * @return 是否新增成功
     */
    @SysLog("新增分销员钱包流水")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserWalletBill:save')")
    public ResponseEntity<Boolean> save(@RequestBody @Valid DistributionUserWalletBill distributionUserWalletBill) {
        return ResponseEntity.ok(distributionUserWalletBillService.save(distributionUserWalletBill));
    }

    /**
     * 修改分销员钱包流水
     *
     * @param distributionUserWalletBill 分销员钱包流水
     * @return 是否修改成功
     */
    @SysLog("修改分销员钱包流水")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserWalletBill:update')")
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid DistributionUserWalletBill distributionUserWalletBill) {
        return ResponseEntity.ok(distributionUserWalletBillService.updateById(distributionUserWalletBill));
    }

    /**
     * 通过id删除分销员钱包流水
     *
     * @param id id
     * @return 是否删除成功
     */
    @SysLog("删除分销员钱包流水")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('distribution:distributionUserWalletBill:delete')")
    public ResponseEntity<Boolean> removeById(@PathVariable Long id) {
        return ResponseEntity.ok(distributionUserWalletBillService.removeById(id));
    }

}
